package zhcms.action;

import java.io.UnsupportedEncodingException;
import java.sql.SQLException;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import zhcms.db.DBManager;
import zhcms.db.ConnectionPool.PooledConnection;
import zhcms.framework.Action;
import zhcms.framework.ActionForward;

public class GySystemInfoAction implements Action{

	@Override
	public ActionForward excute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public ActionForward save(HttpServletRequest request, HttpServletResponse response) {
		try {
			request.setCharacterEncoding("UTF-8");
			response.setContentType("text/html");
			response.setCharacterEncoding("utf-8");
		} 
		catch (UnsupportedEncodingException e1) 
		{
			
		}
		
		String tempSysteminfo="";
		
		tempSysteminfo=getV(request.getParameter("name"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isopen"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("message"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isclose"));
		
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("opentime"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isonline"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("online"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isreg"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isemail"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("isadmin"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("pagecount"));
		
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("url"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("mail"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("mail_n"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("mail_p"));
		tempSysteminfo=tempSysteminfo+","+getV(request.getParameter("mail_s"));
		
		String ishtml=getV(request.getParameter("ishtml"));
		
		String id=getV(request.getParameter("id"));
		
		PooledConnection conn = null;
		String sqlStr1="update `gyhy_System` set `InfoContent`='"+tempSysteminfo+"', `ishtml`='"+ishtml+"' where `id`="+id;
		//System.out.println(sqlStr1);
		boolean isok=false;
		try {
			conn = DBManager.getConnection();
			conn.executeUpdate(sqlStr1);
			conn.close();
			isok=true;
		} catch (SQLException e) {
			isok=false;
			e.printStackTrace();
		}
		finally {
     conn.close();
		}
		
		if(isok==true)
		{
			return new ActionForward("/admin/admin_config.jsp",3,"更新成功");
			//return new ActionForward("/admin/success.jsp?time=30&url=/admin/admin_config.jsp&content=更新成功!",2);
		}
		else
		{
			//out.println("<script language='javascript'>alert('更新错误');location.href=\"/admin/admin_config.jsp\";</script>");
			return new ActionForward("/admin/admin_config.jsp",3,"错误");
		}
	}
	
	private String getV(String S)
	{
		//System.out.println(S);
		String returnS;
		if(S==null || S.length()<=0)
		{
			returnS="";
		}
		else
		{
			returnS=S;
		}
		return returnS;
	}
}
